]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
tests: Port to Gtk4
authorFlorian Müllner <fmuellner@gnome.org>
Wed, 8 Mar 2023 19:25:13 +0000 (20:25 +0100)
committerMarge Bot <marge-bot@gnome.org>
Wed, 7 Jun 2023 11:12:40 +0000 (11:12 +0000)
There's another remaining bit of Gtk3 code in a small test program
that changes a window title to a random character sequence every
five seconds. While the value of that test is a bit questionable,
it doesn't hurt either and a port is trivial.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2733>

tests/interactive/test-title.js

index 0a468ddd506fe44d2bc9fc1b2dde7df4b76c08b6..a147a3a2935b4b2f304ec316616eb61ef6c97546 100755 (executable)
@@ -1,8 +1,7 @@
 #!/usr/bin/env gjs
 
-imports.gi.versions.Gtk = '3.0';
-
-const { GLib, Gtk } = imports.gi;
+imports.gi.versions.Gtk = '4.0';
+const {Gtk} = imports.gi;
 
 function nextTitle() {
     let length = Math.random() * 20;
@@ -16,22 +15,14 @@ function nextTitle() {
     return str;
 }
 
-function main() {
-    Gtk.init(null);
-
-    let win = new Gtk.Window({ title: nextTitle() });
-    win.connect('destroy', () => {
-        Gtk.main_quit();
+const application = new Gtk.Application({application_id: 'org.gnome.TestTitle'});
+application.connect('activate', () => {
+    const win = new Gtk.Window({
+        application,
+        title: nextTitle(),
     });
     win.present();
 
-    GLib.timeout_add(GLib.PRIORITY_DEFAULT, 5000, function() {
-        win.title = nextTitle();
-        return true;
-    });
-
-    Gtk.main();
-}
-
-main();
-
+    setInterval(() => (win.title = nextTitle()), 5000);
+});
+application.run(null);